
AddCSLuaFile( "shared.lua" )

SWEP.Category 		= "HL2 Beta Sweps"
SWEP.PrintName		= "RTB OICW"	
SWEP.Author		= "Valve"
SWEP.Contact		= "n/a"
SWEP.Purpose		= "Kill."
SWEP.Instructions	= "Primary=Shoot Secondary=Grenade."

SWEP.ViewModelFOV	= 55
SWEP.ViewModelFlip	= false
SWEP.ViewModel		= "models/weapons/v_oicw.mdl"
SWEP.WorldModel		= "models/weapons/w_oicw.mdl"
SWEP.AnimPrefix		= "ar2"
SWEP.HoldType		= "ar2"

SWEP.Spawnable			= true
SWEP.AdminSpawnable		= true

SWEP.Primary.ClipSize		= 30			// Size of a clip
SWEP.Primary.DefaultClip	= 90			// Default number of bullets in a clip
SWEP.Primary.Automatic		= true			// Automatic/Semi Auto
SWEP.Primary.Delay		= 0.2
SWEP.Primary.Ammo		= "SMG1"

SWEP.Secondary.ClipSize		= -1			// Size of a clip
SWEP.Secondary.DefaultClip	= -1			// Default number of bullets in a clip
SWEP.Secondary.Automatic	= false			// Automatic/Semi Auto
SWEP.Secondary.Ammo		= "SMG1"

Zoom = 0

function SWEP:Initialize()

end

function SWEP:Holster()
	self.Owner:SetFOV( 0, 0.25 )
	Zoom = 0

	return true
end

function SWEP:Reload()
	if self:DefaultReload( ACT_VM_RELOAD ) then 
		if(SERVER) then
			self.Owner:SetFOV( 0, 0.25 )
			
		end
		self:EmitSound(Sound("weapons/oicw/ar2_reload.wav")) 
         end
end

function SWEP:Think()
end

function SWEP:PrimaryAttack()

	// Make sure we can shoot first
	if ( !self:CanPrimaryAttack() ) then return end

	//Set Delay and Fire
	if (Zoom == 0 || self:Clip1() < 2 ) then
		// Shoot 1 bullet, 10 damage, 0.07 aimcone
		self:ShootBullet( 10, 1, 0.025 )
		// Delay Attack
		self.Weapon:SetNextPrimaryFire( CurTime() + 0.09 )
		// Play shoot sound
		self:EmitSound( Sound("weapons/oicw/ar1_1.wav") )
		// Remove 1 bullet from our clip
		self:TakePrimaryAmmo( 1 )

	end
	
end

function SWEP:SecondaryAttack()
	if self:Clip1() <= 0 then return end
	self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
	self.Weapon:EmitSound( self.Primary.Sound )
	self:SetClip1( self:Clip1() -1 )
	self:LaunchGrenade()	
	self.Weapon:TakePrimaryAmmo( 1 )
	self:SendWeaponAnim(ACT_VM_PRIMARYATTACK)
	self.Owner:SetAnimation( PLAYER_ATTACK1 )
	self.Weapon:SetNetworkedFloat( "LastShootTime", CurTime() )
    end

function SWEP:LaunchGrenade()
	local tracer = self.Owner:GetEyeTrace()

	self.Grenade = ents.Create("env_flare")
	self.Grenade:SetPos(self.Owner:GetShootPos())
	self.Grenade:SetAngles( self.Owner:GetAimVector( ):Angle() )
	self.Grenade:SetKeyValue( "scale", "1" )
	self.Grenade:Spawn()
	self.Grenade:Activate()
	self.Grenade:Fire( "Launch", "2000", 0 )
end